<%@ page 
          import="com.softplus.carrefour.hd.bltier.pc.ICaseHeadViewer,
                         com.softplus.carrefour.hd.bltier.pc.CCaseHeadManage,
                         com.softplus.carrefour.hd.CFHDSystem,
                         com.softplus.carrefour.CFException,
                          com.softplus.carrefour.hd.bltier.entity.UserAccount"
%>
<html>
<head>
<title>auto escalated</title>
</head>
<%
     System.out.println(" * * * * * auto escalated 01  \n  * * * * *  AUTO ESCALATE WARNING 1 MIN");
     UserAccount      userVO            =   (UserAccount) session.getAttribute("userVO");
     String                   userid              =   userVO.getUserId();
     String          viewcasesURL       =   "/CFHD/servlet/com.softplus.carrefour.hd.frontend.servlet.process.CFHDPC01";
     String                  parentObj         =   request.getParameter("updmodal")!=null?"parent.parent":"parent"; //from update modal ?

%>
<script src="../script/Alert.js" type="text/javascript"></script>
<script type="text/javascript">
<!--

     var timeid = 0;
     var timetick = 0;
     var timepopescalate = 0;
     var oneminWin;
     
     function callMe(){
//          window.status = timetick;
		try{
				  //parent.timeTick.innerText = timetick;
				  <%= parentObj %>.frm.checkUnload.value = '';
				  window.location = window.location;
		}catch(error){ }
     }

    function confirmEscalateOneminute(){
          var okSaveButton = " Ok ";
          var cancelSaveButton =" cancel ";
          
           if(showOInfoDialog("Auto escalated", "This case will escalate automatically in 1 minute.", okSaveButton )){
//            showOInfoDialog("Auto escalated", "This case will escalate automatically in 1 minute.", okSaveButton );
               window.clearInterval(timeid);
//               window.location = window.location;
//               timeid = window.setInterval(confirmEscalate,timetick-3000); // triged 3 sec before the real time
           }
     }

    function confirmEscalateLessThanOneminute(){
          var okSaveButton = " Ok ";
          var cancelSaveButton =" cancel ";
          
           if(showOInfoDialog("Auto escalated", "Time for the case will escalate automatically less than 1 minute.", okSaveButton )){
               window.clearInterval(timeid);
//               timeid = window.setInterval(confirmEscalate,timetick-3000); // triged 3 sec before the real time
           }
     }
     
     function confirmEscalate(){
          var okSaveButton = " Ok ";
          var cancelSaveButton =" cancel ";
          
           if(showOInfoDialog("Auto escalated", "This case will escalate automatically", okSaveButton )){
			   		try{
							   window.clearInterval(timeid);
                                      window.clearInterval(timepopescalate);
                                      
							   <%= parentObj %>.frm.checkUnload.value = "autoescalted";
							   <%= parentObj %>.parent.logout.onclick=parent.parent.whenLogout;
							   //parent.location = '<%= viewcasesURL %>';
			   		}catch(error){}
           }
     }
     
-->
</script>
<body>
<button onclick="Javascript:alert('checkUnload#'+parent.frm.checkUnload.value+'#')">parent.frm.checkUnload</button>
<%


      String   caseid4Ae = request.getParameter("caseID") == null ? "none" : request.getParameter("caseID");
      long   remainTime = 0;
      int   timeTicker = 0;
      
      if(!caseid4Ae.equalsIgnoreCase("none")){
                ICaseHeadViewer  headManage  = (CCaseHeadManage) CFHDSystem.getControlClass("CASE_HEAD");
                
                                   remainTime   =  headManage.getCountingTime(caseid4Ae,userid); //userid from MT07

                              System.out.println(" * * * * * CountingTime (set interval) :>"+remainTime);
                
				if(remainTime>0){ //if reamainTime not equals -1, means no auto escalated

//                      remainTime = 10000;  // *** for test
                         out.println(" * * * * * Time Left :>"+remainTime/1000+" sec.");
%>
<script type="text/javascript">
<%
                         long warningPeriod = 60000; //2000 //60000 // 1 minutes.
          
                         out.println(" timetick ="+remainTime+";");
                                        
                              if(remainTime>warningPeriod){ //time remain more than 1 min.
                                   System.out.println(" * * * * * set interval : confirmEscalateOneminute:"+(remainTime-warningPeriod));
                                        if(request.getParameter("updmodal")!=null){
                                                   out.println("  parent.timeid  = window.setInterval(confirmEscalateOneminute,"+(remainTime-warningPeriod)+");"); //time left more then 1 min.
                                        }else{
                                                   out.println("  timeid  = window.setInterval(confirmEscalateOneminute,"+(remainTime-warningPeriod)+");"); //time left more then 1 min.                                        
                                        }
//                                    out.println("  timeid                    = window.setInterval(confirmEscalateOneminute,2000)"); //time left more then 1 min.
                              }else{
                                   System.out.println(" * * * * * confirmEscalateLessThanOneminute");
                                        if(request.getParameter("updmodal")!=null){
                                                  out.println("  parent.confirmEscalateLessThanOneminute(); "); //time left more then 1 min.
                                        }else{
                                                  out.println("  confirmEscalateLessThanOneminute(); "); //time left more then 1 min.                                        
                                        }
                              }

				} //END if reamainTime not equals -1, means no auto escalated
     }
%>
</script>
</body>
</html>
